<%@	page import ="java.util.ArrayList" %>
<%@	page import ="java.util.Iterator" %>
<%@	page import ="java.util.List" %>
<%@	page import ="java.text.SimpleDateFormat" %>

<%@	page import ="com.adisi.objetos.Chofer" %>
<%@	page import ="com.adisi.objetos.TipoDocumento" %>


<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<jsp:directive.include file="headerComun.jsp" />
<body>
	<script type="text/javascript">
	
	$(window).load(function(){
	    $('#formulario').validate({
	        rules: {
	        	chofer_nombre:{
	        		required:true
	        	},
	        	chofer_apellido:"required",
	        	chofer_telefono:{
	        		required:true,
	        		telefono:true
	        	},
	        	chofer_correo:{
	        		email:true
	        	},
	        	chofer_documento:{
	        		documento: true,
	        		required: {
		        		depends: function(element) {
		        	          return ($("#id_tipo_documento").val()>=0);
		        	        }
	        		}
	        	},
	        	chofer_registro:{
	        		documento:true,
	        		required:true
	        	},
	        	chofer_vto_registro:{
	        		fecha:true,
	        		required:true
	        	}
	        	,
	        	chofer_imei: {
	        		digits: true,
					required:{
		        		depends: function(element) {
		        	          return $("#chofer_gps:checked");
		        	        }
	        		}
	        	}
	        },
	        highlight: function(element) {
	            $(element).closest('.form-group').addClass('has-error');
	        },
	        unhighlight: function(element) {
	            $(element).closest('.form-group').removeClass('has-error');
	        },
	        errorElement: 'span',
	        errorClass: 'help-block',
	        errorPlacement: function(error, element) {
	            if(element.parent('.input-group').length) {
	                error.insertAfter(element.parent());
	            } else {
	                error.insertAfter(element);
	            }
	        }
	    });
	
	}); 
</script>


<div class="container">
	<jsp:directive.include file="menuNavegacion.jsp" />
	<div class="row clearfix">
		<div class="col-md-4 column col-md-offset-3">
			<h3>Chofer: </h3>
			
		</div>
	</div>
	<div class="row clearfix">
		<div class="col-md-6 column col-md-offset-3">
			<%
				Chofer chofer = (Chofer)request.getAttribute("chofer");
				String accion = (String)request.getAttribute("accion");			
			%>	
		<script type="text/javascript">
			$(document).ready(function(){
				
				$('#chofer_accion').val('<%=accion%>');
				
				$('#chofer_id').val('<%=chofer.getIdChofer()%>');
				
				<% if(chofer.getIdChofer()!=0){ %>
					
					$('#chofer_nombre').val('<%=chofer.getNombre()%>');
					$('#chofer_apellido').val('<%=chofer.getApellido()%>');
					$('#chofer_telefono').val('<%=chofer.getTelefono()%>');
					$('#chofer_correo').val('<%=chofer.getCorreo() %>');
					$('#chofer_gps').prop('checked', <%=chofer.tieneGPS()?"true":"false" %>);
					$('#chofer_imei').val('<%=chofer.tieneGPS()?chofer.getImei():"" %>');
					$('#chofer_registro').val('<%=chofer.getLicencia().getNumero() %>');
					
					<% if(chofer.getLicencia().getVencimiento()!=null ){ %>
						$('#chofer_vto_registro').val('<%= new SimpleDateFormat("dd/MM/yyyy").format(chofer.getLicencia().getVencimiento()) %>');
						$('#chofer_documento').val('<%=chofer.getDocumento().getNumero() %>');
					<% } %>					

					
					<% if(chofer.getDocumento().getTipo()!=null ){ %>
						$('#id_tipo_documento').val('<%=chofer.getDocumento().getTipo().ordinal() %>');
						$('#chofer_documento').val('<%=chofer.getDocumento().getNumero() %>');
					<% } %>
				<% } %>
				
				
			});
			
		</script>				
			<form role="form" action="chofer" method="post" name="formulario" id="formulario">
				<div class="form-group" style="display:hidden">
					<input type="hidden" id="chofer_id" name="chofer_id"">
					<input type="hidden" id="chofer_accion" name="chofer_accion"">
				</div>			
				<div class="form-group">
					<label for="chofer_nombre">Nombre</label>
					<input type="text" class="form-control" id="chofer_nombre" name="chofer_nombre"	placeholder="Nombre del chofer">
				</div>
				<div class="form-group">
					<label for="chofer_apellido">Apellido</label>
					<input type="text" class="form-control" id="chofer_apellido" name="chofer_apellido" placeholder="Apellido del chofer">
				</div>
				
				<div class="form-group">
					<label for="chofer_documento">Documento</label>
					<div class="row">
						<div class="col-md-4">
							<select name="id_tipo_documento"  id="id_tipo_documento" class="form-control">
								<option value="-1">...</option>
								<%
									TipoDocumento[] tipos = TipoDocumento.values();
									for(TipoDocumento tipoDocumento : tipos) {
									    out.print("<option value=\"");
									    out.print(tipoDocumento.ordinal());
									    out.print("\">");
									    out.print(tipoDocumento.toString());
									    out.println("</option>");
									}
								%>
							</select>							
											
						</div>
						<div class="col-md-8"> 
							<input type="text" class="form-control col-md-3" id="chofer_documento" name="chofer_documento" placeholder="99.999.999">
						</div>
					</div>
				</div>
				<div class="form-group">
					<label for="chofer_telefono">Tel&eacute;fono</label>
					<input type="text" class="form-control" id="chofer_telefono" name="chofer_telefono" placeholder="Tel&ecute;fono del chofer">
				</div>
				<div class="form-group">
					<label for="chofer_correo">Correo</label>
					<input type="text" class="form-control" id="chofer_correo" name="chofer_correo" placeholder="Correo del chofer">
				</div>
				
				<div class="form-group">
					<label for="chofer_registro">Registro nro.</label>
					<input type="text" class="form-control" id="chofer_registro" name="chofer_registro" placeholder="Nro. de registro de conductor del chofer">
				</div>
				
				<div class="form-group">
					<label for="chofer_vto_registro">Vto. del Registro</label>
					<input type="text" class="form-control" id="chofer_vto_registro" name="chofer_vto_registro" placeholder="Fecha de vencimiento del registro" maxlength="10">
				</div>
				
				<div class="form-group">
					<label for="chofer_gps">Tiene gps</label>
					<input type="checkbox" class="form-control" id="chofer_gps" name="chofer_gps" value="1">
				</div>
				
				<div class="form-group">
					<label for="chofer_imei">IMEI del dispositivo</label>
					<input type="text" class="form-control" id="chofer_imei" name="chofer_imei" placeholder="IMEI del dispositivo">
				</div>
				
				<% if(accion.equalsIgnoreCase("editar") || accion.equalsIgnoreCase("agregar")) { %>
				<button type="submit" class="btn btn-primary glyphicon glyphicon-floppy-save"> Grabar</button>
				<% } else if(accion.equalsIgnoreCase("borrar")) { %>				
				<button type="submit" class="btn btn-danger glyphicon glyphicon-trash" value="Borrar" onclick="return confirm('Esta seguro?')"> Borrar</button>
				<% } %>
				<a  href="chofer?lst" type="cancel" class="btn btn-warning glyphicon glyphicon-ban-circle"> Cancelar</a>
				
			</form>

					

		</div>
	</div>
</div>

</body>
</html>